import { Injectable } from '@nestjs/common';
import { createTransport, Transporter } from "nodemailer";

@Injectable()
export class EmailService {
    transporter: Transporter;

    constructor() {
        this.transporter = createTransport({
            host: "smtp.qq.com", // 网易邮箱授权码失效改用qq邮箱
            port: 587,
            secure: false,
            auth: {
                user: '415096996@qq.com',
                pass: 'dezmucqovurjbijb'
            },
            debug: true, 
        });
    }

    async sendMail({ to, subject, html }) {
        await this.transporter.sendMail({
            from: {
                name: '聊天室',
                address: '415096996@qq.com'
            },
            to,
            subject,
            html
        });
    }
}
